<html>
<head>
	<title>Ultimate Google Docs Viewer Options</title>
    <script src='js/jquery.js'></script>
    <script type="text/javascript">
		var timeout;
		// alter this to add or remove extensions
		var ext_obj = {
			"<img src='images/spread.gif' align='absmiddle' /> Speadsheet Extensions"	: [
				/*"xls",
				"xlsx",
				"ods",
				"csv",
				"tsv",
				"txt",
				"tsb"*/
			],
			"<img src='images/doc.gif' align='absmiddle' /> Document Extensions": [
				"doc",
				"docx",
				"pdf",
				"tiff"
				/*"rtf",
				"sxw"*/
			],
			"<img src='images/pres.gif' align='absmiddle' /> Presentation Extensions":[
				"ppt",
				"pps"
			]
			
		}
        // Saves options to localStorage.
        function saveOptions() {
			for (var ext_sec in ext_obj){
				for(var i = 0; i < ext_obj[ext_sec].length; i++){
					var current_ext = ext_obj[ext_sec][i];
					localStorage["ugdv_" + current_ext] = $('#'+ current_ext).attr('checked');
				}
			}
			localStorage["ugdv_newTab"] = $("#new_page").attr('checked');
			localStorage["ugdv_useDocsLink"] = $("#use_docs_link").attr('checked');
			$("#status").html("Saved!").show();
			clearInterval(timeout);
			timeout = setInterval(hideStatus, 2000);
        }
		function hideStatus(){
			clearInterval(timeout);
			$("#status").fadeOut("fast");
		}
        function presetValues(){
			var checked = true;
			for (var ext_sec in ext_obj){
				for(var i = 0; i < ext_obj[ext_sec].length; i++){
					var current_ext = ext_obj[ext_sec][i];
					checked = localStorage["ugdv_" + current_ext] != null ? toBool(localStorage["ugdv_" + current_ext]) : true;
					$('#'+current_ext).attr('checked', checked);
					$('#'+current_ext).onchange = function(){
						$("#status").html("Not saved");
					}
				}
			}
			checked = localStorage["ugdv_newTab"] != null ? toBool(localStorage["ugdv_newTab"]) : true;
			$("#new_page").attr('checked', checked); 
			checked = localStorage["ugdv_useDocsLink"] != null ? toBool(localStorage["ugdv_useDocsLink"]) : true;
			$("#use_docs_link").attr('checked', checked);
			$("#new_page").change(function(e){
				$("#status").html("Not saved").show();
			});
			$("#use_docs_link").change(function(e){
				$("#status").html("Not saved").show();
			});
			$("#status").hide()
        }
		function toBool(str){
			return ("false" === str) ? false : true;
		}
		function selectAll(){	
			for (var ext_sec in ext_obj){
				for(var i = 0; i < ext_obj[ext_sec].length; i++){
					var current_ext = ext_obj[ext_sec][i];
					$('#'+current_ext).attr('checked', true);
				}
			}
			$("#status").html("Not saved").show();
			clearInterval(timeout);
		}
		function deselectAll(){
			for (var ext_sec in ext_obj){
				for(var i = 0; i < ext_obj[ext_sec].length; i++){
					var current_ext = ext_obj[ext_sec][i];
					$('#'+current_ext).attr('checked', false);
				}
			}
			$("#status").html("Not saved").show();
			clearInterval(timeout);
		}
    </script>
    <style>
		html{
			font-family:Arial, Helvetica, sans-serif;
		}
		form {
			background-color:#F5F5F5;
			border: #E5E5E5 1px solid;
			padding: 20px;
			width: 400px;
		}
		#page_title {
			color:#039;
			font-weight:bold;
			font-family: Arial, Helvetica, sans-serif;
			font-size:24px;
			margin-bottom:14px;
		}
		.section {
			color:#039;
			font-weight:bold;
			font-family: Arial, Helvetica, sans-serif;
			font-size:14px;
			margin:15px 0 4px 0;
		}
		label {
			margin-left: 20px;	
		}
		#notice {
			margin-top: 20px;
			font-size:10px;
			font-weight:bold;
		}
		#status {
			font-size:10px;
			font-weight:bold;
			color:#039;
		}
	</style>

</head>

<body onLoad="presetValues()">
    <div id="page_title"><img src="images/icon48.png" align="absmiddle" /> Configure the Ultimate Google Docs Viewer</div>
    <form action="javascript:void(0);">
        <script type="text/javascript">
            for (var ext_sec in ext_obj){
                document.write("<div class='section'>" + ext_sec + "</div>");
				if (ext_obj[ext_sec].length > 0){
					for(var i = 0; i < ext_obj[ext_sec].length; i++){
						var current_ext = ext_obj[ext_sec][i];
						document.write("<label><input type='checkbox' id='" + current_ext + "' /> *."+current_ext+"</label><br />");
					}
				}else{
					document.write("<i>No files of this type are yet supported by the viewer.</i>");
				}
            }
        </script>
        <br />
        <button onClick="selectAll();"><img src='images/checkbox.png' align='absmiddle' /> Select All</button>
	    <button onClick="deselectAll();"><img src='images/uncheckbox.png' align='absmiddle' /> Select None</button>
    </form>
    <label><input type='checkbox' id='new_page' /> Open links in new tab/window </label><br />
    <label><input type='checkbox' id='use_docs_link' /> Show import link on Google Docs Viewer</label><br />
	<br />
    <div id="status"></div>
    <button onClick="saveOptions();"><img src='images/disk.png' align='absmiddle' /> Save</button>
    <button onClick="window.close();"><img src='images/cross.png' align='absmiddle' /> Close Options</button>

<div id="notice">
	NOTE: Google Docs restricts web import; document sizes: 500KB, presentations: 2MB. 
    <br /><br />
    When uploading files, you agree to abide by the Google Docs Terms of Service and Privacy Policy. Do not upload <br />
    or share any content that infringes copyrights or that you otherwise do not have the legal right to upload or share. <br />
    <a href="http://www.google.com/google-d-s/terms.html" target="_blank">Learn more.</a>
    <br /><br />
	* Icons used on the form, title, and extension app icon are owned by <a href="http://www.google.com" target="_blank">Google, Inc.</a>.
    <br />
    * Icons on buttons are from <a href="http://famfamfam.com" target="_blank">famfamfam.com</a>
    <br /><br />
    For bugs or suggestions, please leave a comment on the extension page or email me at <a href="mailto:ext.chrome@gmail.com">ext.chrome@gmail.com</a>
    
</div>
</body>
</html>